import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
import { useUserStore } from '/@/store/modules/user';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '起始编号',
    align: 'center',
    dataIndex: 'serialNumberSuffix',
  },
  {
    title: '末尾编号',
    align: 'center',
    dataIndex: 'serialNumberSuffix',
    customRender: ({ text }) => {
      // 将文本转换为数字，并加199
      const number = parseInt(text, 10) + 199;
      // 转换回字符串，并检查长度是否超过10个字符
      let result = number.toString();
      if (result.length > 10) {
        result = result.substr(0, 10);
      }
      return result;
    },
  },
  {
    title: '个数',
    align: 'center',
    dataIndex: 'boxTotal',
  },
  {
    title: '入库日期',
    align: 'center',
    dataIndex: 'createTime',
  },
  {
    title: '是否出库',
    align: 'center',
    dataIndex: 'isRetrieval',
    customRender: ({ text }) => {
      // 根据值显示相应的文本
      return text === 1 ? '是' : '否';
    },
  },
  {
    title: '操作人员',
    align: 'center',
    dataIndex: 'createBy',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '起编号',
    field: 'serialNumberSuffix',
    component: 'InputNumber',
  },
  {
    label: '操作人员',
    field: 'collectingBy_dictText',
    component: 'JSelectUser',
  },
  {
    label: '入库日期',
    field: 'createTime_begin',
    // field: 'createTime_end',
    component: 'RangeDate',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
    },
  },
];
//表单数据
const userStore = useUserStore();
const userInfo = userStore.getUserInfo;
const data = userInfo.orgCode;
export const formSchema: FormSchema[] = [
  {
    component: 'JSelectUserByDept',
    field: 'collectingBy',
    label: '领取人员',
    helpMessage: ['component模式'],
    componentProps: {
      maxSelectCount: 1, // 最大选择数
      // params: { orgCode: data },
      labelKey: 'realname',
      rowKey: 'username',
    },
    rules: [{ required: true, message: '请选择领取人员' }],
  },
  {
    label: '起始编号',
    field: 'serialNumberSuffix',
    component: 'Input',

    componentProps: {
      disabled: true, // 禁用输入，防止用户手动更改
    },
  },
  {
    label: '出库数量',
    field: 'boxTotal',
    component: 'Input',
    componentProps: {
      disabled: true, // 禁用输入，防止用户手动更改
    },
  },
  {
    label: '箱子ID',
    field: 'id',
    component: 'Input',
    rules: [{ required: true, trigger: 'blur' }],
    componentProps: {
      readOnly: true, // 设置为只读
    },
    show: false,
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  dateProduction: { title: '出厂日期', order: 0, view: 'date', type: 'string' },
  manufacturer: { title: '生产厂家', order: 1, view: 'text', type: 'string' },
  boxTotal: { title: '个数', order: 2, view: 'number', type: 'number' },
  batch: { title: '批次（年月）', order: 3, view: 'text', type: 'string' },
  isRetrieval: { title: '是否出库', order: 4, view: 'select', type: 'string' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
